# Maintainer: Sven-Hendrik Haase <svenstaro@gmail.com>
# Contributor: Dave Reisner <dreisner@archlinux.org>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Douglas Soares de Andrade
# Contributor: Roberto Alsina <ralsina@kde.org>

pkgname=varnish
pkgver=7.0.0
pkgrel=1
pkgdesc="High-performance HTTP accelerator"
arch=('x86_64')
url="https://www.varnish-cache.org/"
license=('BSD')
depends=('gcc' 'libnsl' 'pcre2')
makedepends=('python-docutils' 'python-sphinx' 'git')
optdepends=('python: needed for vmod development')
backup=('etc/varnish/default.vcl')
install=$pkgname.install
source=("https://varnish-cache.org/_downloads/varnish-$pkgver.tgz"
        "git+https://github.com/varnishcache/pkg-varnish-cache.git#commit=d3e6a3f"
        varnish.sysusers)
sha512sums=('39c694db4ec7b35236d12fe2c03036260d6799395b1c8bb5a58e96fc88d67dcaa5eb8bc75643540d3aa0edc1a8924d7d839e88293b0521fadef4cd12f466fb4b'
            'SKIP'
            '1eeeba4ab990c1790495f9ff4625ad37f21e155e08e0c255e09d18c44054f3a59613b81c07d8701610b0b266e5181ae8bbae2523138737f3c4f0e1a6c287bb0c')

prepare() {
  cd "varnish-$pkgver"

  ./autogen.sh
}

build() {
  cd "varnish-$pkgver"

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var/lib \
    --sbindir=/usr/bin

  make
}

# check() {
#   cd "varnish-$pkgver"
#
#   make check
# }

package() {
  cd "varnish-$pkgver"

  make DESTDIR="$pkgdir" install

  install -Dm644 "$srcdir/pkg-varnish-cache/systemd/varnish.service" "$pkgdir/usr/lib/systemd/system/varnish.service"
  install -Dm644 "$srcdir/pkg-varnish-cache/systemd/varnishncsa.service" "$pkgdir/usr/lib/systemd/system/varnishncsa.service"
  install -Dm755 "$srcdir/pkg-varnish-cache/systemd/varnishreload" "$pkgdir/usr/bin/varnishreload"
  install -Dm755 "$srcdir/pkg-varnish-cache/systemd/varnish.logrotate" "$pkgdir/etc/logrotate.d/varnish"

  # create varnish:varnish user/group
  install -Dm644 "$srcdir/varnish.sysusers" "$pkgdir/usr/lib/sysusers.d/varnish.conf"

  # config
  install -Dm644 "etc/example.vcl" "$pkgdir/etc/varnish/default.vcl"
  install -Dm644 "etc/builtin.vcl" "$pkgdir/usr/share/doc/varnish/builtin.vcl"

  # license
  install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
